﻿@{
    ViewBag.Title = "Schedule";            
}
@model DLULearningNetwork.ViewModels.ScheduleViewModel
<style type="text/css">
    table.tbl1 th
    {
        width: 96px;
        text-align: center;
    }
    
    table.tbl1 td
    {
        border-color: #dfffb2;
    }
    
    table.tbl1 tr.day td
    {
        background-color: #dfe1e3;
        font-weight: bold;
        height: 17px;
        line-height: 17px;
    }
    
    table.tbl1 tr.scheInfo td.off
    {
        background-color: #bfbfbf;
    }
    
    table.tbl1 tr.scheInfo td.off:hover
    {
        background-color: #bfbfbf;
    }
    
    table.tbl1 tr.scheInfo td.invalid
    {
        background-color: #543434;
    }
    
    table.tbl1 tr.scheInfo td.invalid:hover
    {
        background-color: #543434;
    }
    
    table.tbl1 tr.scheInfo td
    {
        height: 60px;
        line-height: 60px;
        text-align: center;
    }
    
    table.tbl1 tr.scheInfo td:hover
    {
        background-color: #ebfdd2;
    }
</style>
<script type="text/javascript">
    $(document).ready(function () {
        Schedule.init();       
    });
</script>
<div class="loading" id="scheduleLoading">
</div>
<div style="width:100%; text-align:center;">
<select id="scheduleMonth">
    @for (int i = 1; i <= 12; i++)
    {
        if (i == Model.Month)
        {
        <option value="@i" selected="selected">@i</option>
        }
        else
        { 
        <option value="@i">@i</option>
        }
    }
</select>
<select id="scheduleYear">    
    @{
        int currYear = DateTime.Now.Year;
        for (int i = currYear - 10; i <= currYear + 10; i++)
        {
            if (i == Model.Year)
            {
        <option value="@i" selected="selected">@i</option>
            }
            else
            { 
        <option value="@i">@i</option>
            }
        }        
    }
</select>
<input id="btnGetSeminarSchedule" type="button" class="button" value="Xem" />
</div>
<div class="clearall"></div>
<table id="scheduleTable" class="tbl1" style="width: 672px; margin: 3px auto 3px auto; border-color: #dfffb2;"
    cellpadding="0" cellspacing="0" border="1" courseID="@Model.CourseID">
    <tr>
        <th>
            Chủ nhật
        </th>
        <th>
            Thứ 2
        </th>
        <th>
            Thứ 3
        </th>
        <th>
            Thứ 4
        </th>
        <th>
            Thứ 5
        </th>
        <th>
            Thứ 6
        </th>
        <th>
            Thứ 7
        </th>
    </tr>
    @{MvcHtmlString str = new MvcHtmlString("class=\"off\"");      
      int count = 0;
      bool firstLoop = true;
    }
    @for (int i = 1; i <= Model.DaysInMonth; i += 7)
    {
        if (i == 1 && firstLoop)
        {
        <tr class="day">
            @for (int j = 0; j < Model.FirstDayInMonth; j++)
            { 
                <td>
                    &nbsp;
                </td>
                count++;
            }
            @for (int x = 1; x <= 7 - count; x++)
            { 
                <td>
                    @if (x <= Model.DaysInMonth)
                    { @(x) }
                    else
                    { <span>&nbsp;</span> }
                </td>
            }
        </tr>
        }
        else
        {
        <tr class="day">
            <td>@i
            </td>
            <td>
                @if (i + 1 <= Model.DaysInMonth)
                { @(i + 1) }
                else
                { <span>&nbsp;</span> }
            </td>
            <td>
                @if (i + 2 <= Model.DaysInMonth)
                { @(i + 2) }
                else
                { <span>&nbsp;</span> }
            </td>
            <td>
                @if (i + 3 <= Model.DaysInMonth)
                { @(i + 3) }
                else
                { <span>&nbsp;</span> }
            </td>
            <td>
                @if (i + 4 <= Model.DaysInMonth)
                { @(i + 4) }
                else
                { <span>&nbsp;</span> }
            </td>
            <td>
                @if (i + 5 <= Model.DaysInMonth)
                { @(i + 5) }
                else
                { <span>&nbsp;</span> }
            </td>
            <td>
                @if (i + 6 <= Model.DaysInMonth)
                { @(i + 6) }
                else
                { <span>&nbsp;</span> }
            </td>
        </tr>
        }

        if (i == 1 && firstLoop)
        {
            count = 0;
        <tr class="scheInfo">
            @for (int j = 0; j < Model.FirstDayInMonth; j++)
            { 
                <td class="off">
                    &nbsp;
                </td>
                count++;
            }
            @for (int x = 1; x <= 7 - count; x++)
            {
                if (!Model.CheckCurDayIsValidOrNot(x))
                {
                    <td class="invalid">&nbsp;</td>
                }
                else
                {
                <td @if (x > Model.DaysInMonth)
                    {@str} 
                    day="@x" month="@Model.Month" year="@Model.Year">
                    @if (Model.CheckCurDayHaveScheduleOrNot(x))
                    {
                        <span class="pin_icon40"></span>
                    }
                    else
                    {
                        <span class="free">&nbsp;</span>
                    }
                </td>
                } 
            }
        </tr>
        }
        else
        {
        <tr class="scheInfo">
            @for(int j = i; j <= i + 6; j++)
            {
                if(j > Model.DaysInMonth)
                {
                <td class="off">&nbsp;</td>
                }
                else if (!Model.CheckCurDayIsValidOrNot(j))
                {
                <td class="invalid">&nbsp;</td>
                }
                else
                {
                <td day="@j" month="@Model.Month" year="@Model.Year">
                    @if (Model.CheckCurDayHaveScheduleOrNot(j))
                    {
                        <span class="pin_icon40"></span>
                    }
                    else
                    {
                        <span class="free">&nbsp;</span>
                    }
                </td>
                }
            }      
        </tr>   
        }

        if (firstLoop)
        {
            i = (8 - Model.FirstDayInMonth) - 7;
            firstLoop = false;
        }
    }
</table>
